package com.daocheng.weblog.common.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName JsonUtil
 * @description: JSON工具类
 * @author: 稻城
 * @date: 2025/3/3
 * @Version 1.0
 */
@Slf4j
public class JsonUtil {
    private static final ObjectMapper INSTANCE = new ObjectMapper();

    /**
     * @return java.lang.String
     * @author 稻城
     * @description
     * @Date 2025/3/3 1:04
     * @Param object
     */
    public static String toJsonString(Object object) {
        try {
            return INSTANCE.writeValueAsString(object);
        } catch (Exception e) {
            log.error("JSON序列化失败", e);
            return object.toString();
        }
    }
}
